package net.atomarrow.controllers.converter;

import java.sql.Time;

import net.atomarrow.util.DateUtil;
import net.atomarrow.util.StringUtil;

public class TimeConverter implements IConverter {

    @Override
    public boolean canHandle(Class clazz) {
        return clazz == Time.class;
    }

    @Override
    public <T> T converter(Object[] values, Class<T> clazz) throws Exception{
        Object value =values[0];
        if(value==null||StringUtil.isBlank(value.toString())){
            return null;
        }
        Time time =  DateUtil.getTime(value.toString());
        if(time==null){
            throw new RuntimeException("can not convert "+ value);
        }
        return (T)time;
    }
}
